// component/modal/modal.js
var app = getApp();
var Ajax = require('../../utils/Ajax.js');
var utils = require('../../utils/util.js');
var wxDecodeObj = require("../../utils/wxDecode.js");
Component({
  properties: {
    zIndex: {//弹窗层级
      type: Number,
      value: 999
    },
    mandatory:{//是否需要强制授权步数
      type: Boolean,
      value: false
    },
    overflow: {//盒子是否超出隐藏
      type: String,
      value: "hidden"
    },
    height: {//弹窗主体高度
      type: String,
      value: "552rpx"
    },
    width: {//弹窗主体宽度
      type: String,
      value: "550rpx"
    },
    autoClose: {
      type: Boolean,
      value: true
    },
    transparent: {//弹窗主体背景是否需要透明
      type: Boolean,
      value: false
    },
    showCancel: {//是否显示取消按钮
      type: Boolean,
      value: false
    },
    popupconnet: {//提示框标题
      type: String,
      value: '提示'
    },
    canceltext: {//默认取消按钮文字
      type: String,
      value: '取消'
    },
    confirmtext: {//默认确定按钮文字
      type: String,
      value: '确定'
    },
    
    imgurl: {//可指定弹窗的img
      type: String,
      value: '/assets/img/warning.png'
    },
    bindcancel: {//取消按钮的事件名称
      type: String,
      value: ''
    },
    bindconfirm: {//确定按钮的事件名称
      type: String,
      value: ''
    },
    confirmtips: {//img下面默认提示语
      type: String,
      value: '开票金额为实际支付金额'
    },
    showTips: {//是否显示提示语
      type: Boolean,
      value: false
    },
    showOneBtn: {//是否显示确定按钮
      type: Boolean,
      value: false
    },
    samllimg:{//小的imgcss
      type: Boolean,
      value: false
    },
    showImg: {//是否显示图片
      type: Boolean,
      value: true
    },
    slotData: {//是否显示模版
      type: Boolean,
      value: false
    },
    showScroll: {//是否显示协议
      type: Boolean,
      value: false
    },
    showScrollx: {//Scroll横向滚动
      type: Boolean,
      value: false
    },
    scrollWidth: {//Scroll横向滚动
      type: String,
      value: '630rpx'
    },
    scrollHeight: {//协议的Scroll盒子默认高度
      type: String,
      value: "560rpx"
    },
    showScrollData: {//是否显示模版
      type: Boolean,
      value: false
    },
    showconfirmbtncss:{//确认按钮的样式
      type: Boolean,
      value: false
    },
    showTitle: {//是否显示弹窗标题
      type: Boolean,
      value: true
    },
    isclose:{
      type:Boolean,
      value:false
    },
    showGetuid: {
      type: Boolean,
      value: false
    },
    onebtncolor:{
      type: String,
      value: "#fff"
    },
    onebackground:{
      type: String,
      value: "#18DBBE"
    },
    isH5: {
      type: Boolean,
      value: false
    },
    h5link: {
      type: String,
      value: ""
    },
    rightClose: {
      type: Boolean,
      value: false
    },
    _isMaskClose: {//是否点击mask关闭弹窗
      type: Boolean,
      value: false
    },
  },
  data: {
    _showData: false,
    animation: null
  },
  methods: {
    show() {
      if (this.data._showData) {
        return;
      }
      this.setData({
        _showData: true
      })
    },
    hide() {
      if (!this.data._showData) {
        return;
      }
      setTimeout(() => {
        this.setData({
          _showData: false
        })
      }, 200);
    },
    isShow() {
      return this.data._showData;
    },
    catchEvent(e) {
      if (this.properties.autoClose) {
        this.hide();
      }
    },
    catchEventContent() {

    },
    onCancel(e) {
      var { bindcancel } = e.currentTarget.dataset;
      !bindcancel && this.catchEvent();//默认关闭弹窗
      bindcancel && this.triggerEvent("" + bindcancel, e.currentTarget.dataset);
    },
    onDetermine(e) {
      var { bindconfirm } = e.currentTarget.dataset;
      !bindconfirm && this.catchEvent();//默认关闭弹窗
      bindconfirm && this.triggerEvent(''+bindconfirm, e.currentTarget.dataset);
    },
    //授权之后的回调
    getUid(e){
      var that = this 
      if (e.detail.userInfo){
        app.autoLoginNew(e.detail, (state,msg)=>{
          if (state){
            !this.properties.mandatory&&this.triggerEvent('upDatastepUi');
            if (this.properties.mandatory) {
              app.getWeRun((status, msg) => {
                if (status) {
                  this.triggerEvent('upDatastepUi', msg.data)
                }
              }, true, true);
            }
            this.hide()
          }
        })
      }else{
        console.log('已拒绝')
      }
    }
  }
})
